home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifMenuItemUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  129 lines

  1. /*
  2.  * @(#)MotifMenuItemUI.java    1.36 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.motif;
  22.  
  23.  
  24. import com.sun.java.swing.*;
  25. import com.sun.java.swing.event.*;
  26. import java.awt.*;
  27. import java.awt.event.*;
  28. import java.io.Serializable;
  29.  
  30. import com.sun.java.swing.plaf.*;
  31. import com.sun.java.swing.plaf.basic.BasicMenuItemUI;
  32. import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
  33.  
  34.  
  35. /**
  36.  * MotifMenuItem implementation
  37.  * <p>
  38.  * Warning: serialized objects of this class will not be compatible with
  39.  * future swing releases.  The current serialization support is appropriate
  40.  * for short term storage or RMI between Swing1.0 applications.  It will
  41.  * not be possible to load serialized Swing1.0 objects with future releases
  42.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  43.  * baseline for the serialized form of Swing objects.
  44.  *
  45.  * @author Rich Schiavi
  46.  * @author Georges Saab
  47.  */
  48. public class MotifMenuItemUI extends BasicMenuItemUI
  49. {
  50.     protected ChangeListener changeListener;
  51.  
  52.     public static ComponentUI createUI(JComponent c) 
  53.     {
  54.     return new MotifMenuItemUI();
  55.     }
  56.     
  57.     protected void initListeners(JComponent c) {
  58.     super.initListeners(c);
  59.         changeListener = createChangeListener(c);
  60.     }
  61.     
  62.     protected void addListeners(JComponent c) {
  63.     super.addListeners(c);
  64.         ((JMenuItem)c).addChangeListener(changeListener);    
  65.     }
  66.  
  67.     protected void removeListeners(JComponent c) {
  68.     super.removeListeners(c);
  69.     ((JMenuItem)c).removeChangeListener(changeListener);
  70.     }
  71.  
  72.     protected ChangeListener createChangeListener(JComponent c) {
  73.     return new MenuChangeListener();
  74.     }
  75.  
  76.     public Dimension getPreferredSize(JComponent c) {
  77.     return BasicGraphicsUtils.getPreferredMenuItemSize(c,
  78.                    checkIcon, menuArrow, defaultTextIconGap);
  79.     }
  80.  
  81.     public void paint(Graphics g, JComponent c) {
  82.     MotifGraphicsUtils.paintMenuItem(g, c, checkIcon,menuArrow,
  83.                      pressedBackground, pressedForeground,
  84.                      defaultTextIconGap);
  85.     }
  86.  
  87.  
  88.     public void processMouseEvent(JMenuItem item,MouseEvent e,MenuElement path[],MenuSelectionManager manager) {
  89.         Point p = e.getPoint();
  90.         if(p.x >= 0 && p.x < item.getWidth() &&
  91.            p.y >= 0 && p.y < item.getHeight()) {
  92.             if(e.getID() == MouseEvent.MOUSE_RELEASED) {
  93.                 manager.clearSelectedPath();
  94.                 item.doClick(0);
  95.                 item.setArmed(false);
  96.             } else if(e.getID() == MouseEvent.MOUSE_DRAGGED || e.getID() == MouseEvent.MOUSE_PRESSED)
  97.                 manager.setSelectedPath(path);
  98.         } else if(e.getID() == MouseEvent.MOUSE_RELEASED) {
  99.             manager.clearSelectedPath();
  100.         } else if(item.getModel().isArmed() && e.getID() == MouseEvent.MOUSE_DRAGGED) {
  101.             MenuElement newPath[] = new MenuElement[path.length-1];
  102.             int i,c;
  103.             for(i=0,c=path.length-1;i<c;i++)
  104.                 newPath[i] = path[i];
  105.             manager.setSelectedPath(newPath);
  106.         }
  107.     }
  108.  
  109.     protected class MenuChangeListener implements ChangeListener, Serializable {
  110.  
  111.     public void stateChanged(ChangeEvent e) {
  112.         JMenuItem c = (JMenuItem)e.getSource();
  113.         if (c.isArmed() || c.isSelected()) {
  114.         c.setBorderPainted(true);
  115.         } else {
  116.         c.setBorderPainted(false);
  117.         }
  118.     }
  119.     }
  120.   
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.